package com.laixu;

import com.laixu.bean.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

public class MainApp {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 从Spring容器中获取所有Bean
        Category category = context.getBean(Category.class);
        Book book = context.getBean(Book.class);
        User user = context.getBean(User.class);
        Order order = context.getBean(Order.class);
        Address address = context.getBean(Address.class);
        OrderItem orderItem = context.getBean(OrderItem.class);
        Chopcar chopcar = context.getBean(Chopcar.class);
        Collect collect = context.getBean(Collect.class);
        Logg logg = context.getBean(Logg.class);

        // 打印所有 Bean 名称
        String[] beanNames = context.getBeanDefinitionNames();
        Arrays.stream(beanNames).forEach(System.out::println);
        // 验证对象是否成功创建
        System.out.println("Category Bean: " + category);
        System.out.println("Book Bean: " + book);
        System.out.println("User Bean: " + user);
        System.out.println("Order Bean: " + order);
        System.out.println("Address Bean: " + address);
        System.out.println("OrderItem Bean: " + orderItem);
        System.out.println("Chopcar Bean: " + chopcar);
        System.out.println("Collect Bean: " + collect);
        System.out.println("Logg Bean: " + logg);
    }
}